<template>
  <view class="view" :style="{height: viewHeight}">
    <view class="tab">
      <uni-segmented-control
          class="top-tab"
          :current="tabActive"
          :values="items"
          style-type="text"
          @clickItem="onTabChange"/>
    </view>
    <scroll-view
        class="container"
        :scroll-y="true"
    >
      <!--审核中-->
      <view v-if="tabActive === 0" class="reviewing">
        <none-data v-if="reviewingDataList.length===0"/>
        <view v-else class="review-msg">
          <review-msg-item
              v-for="review in reviewingDataList"
              :key="review.id"
              :title="review.honorName"
              :desc="review.honorDetail"
          />
        </view>
      </view>
      <!--已完成-->
      <view v-if="tabActive === 1" class="completed">
        <none-data v-if="completedDataList.length===0"/>
        <view v-else class="review-msg">
          <review-msg-item
              v-for="review in completedDataList"
              :key="review.id"
              :title="review.honorName"
              :desc="review.honorDetail"
          />
        </view>
      </view>
      <!--未通过-->
      <view v-if="tabActive === 2" class="refused">
        <view class="review-msg">
          <none-data v-if="refusedDataList.length===0"/>
          <review-msg-item
              v-else
              v-for="review in refusedDataList"
              :key="review.id"
              :title="review.honorName"
              :desc="review.honorDetail"
              @click="toRefuseDetail(review)"
          />
        </view>
      </view>
    </scroll-view>
  </view>
</template>
<script setup>
import {ref, onMounted, nextTick} from 'vue'
import UniSegmentedControl
  from "@/uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.vue";
import reviewMsgItem from './componments/review-msg-item.vue'
import {getTitleViewHeight} from "@/utils/utils";
import {getUploadDataReviewStageListApi} from "@/api/user";

const viewHeight = ref('')
const tabActive = ref(0)
const items = ref(['审核中', '已完成', '未通过'])

const reviewingDataList = ref([]) //审核中数据
const completedDataList = ref([]) // 已完成数据
const refusedDataList = ref([]) // 未通过数据

const onTabChange = (val) => {
  tabActive.value = val.currentIndex
}

const getUploadDataList = async () => {
  const params = {
    type: 2
  }
  const res = await getUploadDataReviewStageListApi(params)
  const {code, data} = res
  if (code === 200) {
    reviewingDataList.value = Array.isArray(data) && data.filter(item => item.checkStatus === '0')
    completedDataList.value = Array.isArray(data) && data.filter(item => item.checkStatus === '1')
    refusedDataList.value = Array.isArray(data) && data.filter(item => item.checkStatus === '2')
  }
}

const toRefuseDetail = (review) => {
  uni.navigateTo({
    url: `/package_user/pages/user/refuse`,
    success: res => {
      res.eventChannel.emit('getReviewData', review)
    }
  })
}

onMounted(() => {
  getUploadDataList()
  nextTick(() => {
    viewHeight.value = `calc(100vh - ${getTitleViewHeight() + 20}rpx)`
  })
})
</script>
<style scoped lang=less>
.view {
  padding-top: 20rpx;
  box-sizing: border-box;
  background-color: @color-font;
  overflow:auto;

  .tab {
    position: fixed;
    top: var(--window-top);
    width: 100%;
    z-index: 999;
    background-color: @color-font;
  }

  .container {
    margin-top: 36rpx;
    .reviewing,
    .completed,
    .refused{
      padding: 0 20rpx;
    }
  }
}

</style>
